package com.ruoyi.dictionary.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.dictionary.Service.RicePestsService;
import com.ruoyi.dictionary.domain.RicePests;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author DELL
 */
@Api("水稻害虫-电子词典")
@RestController
@RequestMapping("/dic/ricepests")
public class RicePestsController extends BaseController {

    @Autowired
    private RicePestsService ricePestsService;

    /**
     * 查询水稻害虫图文库列表
     */
    @ApiOperation("查询水稻害虫列表")
    @GetMapping("/list")
    public TableDataInfo list(RicePests ricePests) {
        startPage();
        List<RicePests> list = ricePestsService.selectRicePestsList(ricePests);
        return getDataTable(list);
    }

    /**
     * 新增水稻害虫图文库
     */
    @ApiOperation("新增水稻害虫")
    @PostMapping
    public AjaxResult add(@RequestBody RicePests ricePests) {
        return toAjax(ricePestsService.insertRicePests(ricePests));
    }

    /**
     * 删除水稻害虫数据（根据RicePestID）
     *
     * @param ricePestsIds
     * @return
     */
    @ApiOperation("删除水稻害虫")
    @DeleteMapping("/{ricePestsIds}")
    public AjaxResult remove(@PathVariable Long[] ricePestsIds) {
        return toAjax(ricePestsService.deleteRicePestsByIds(ricePestsIds));
    }

    /**
     * 修改水稻害虫信息
     *
     * @param ricePests
     * @return
     */
    @ApiOperation("修改水稻害虫")
    @PutMapping
    public AjaxResult edit(@RequestBody RicePests ricePests) {
        return toAjax(ricePestsService.updateRicePests(ricePests));
    }

}
